package state;

public class SMSHandler implements Runnable {
  private static SMSHandler inst = new SMSHandler();
  private SendSMSListener listener = null;

  // TODO: Particle: chưa làm được phần SMS
  private SMSHandler() {
  }

  public static SMSHandler getInstance(SendSMSListener listener) {
    inst.listener = listener;
    return inst;
  }

  private String mReceiver = null;
  private String mPort = null;
  private String msgString = null;
  private boolean mSending = false;

  public void sendMsg(String callNumber, String messageText) {
    sendMsg(callNumber, null, messageText);
  }

  public void sendMsg(String callNumber, String port, String messageText) {
    if (mSending) {
      return;
    }
    mReceiver = callNumber;
    mPort = port;
    msgString = messageText;
    Thread th = new Thread(this);
    th.start();
  }

  public boolean isSending() {
    return mSending;
  }

  // Send the color message
  public void run() {
// mSending = true;
// try {
// sendSMS();
// if (listener != null) {
// listener.onSendSMSSuccess();
// }
// } catch (Exception e) {
// if (listener != null) {
// listener.onSendSMSFail();
// }
// }
// mSending = false;
  }

// private void sendSMS() {
// StringBuffer address = new StringBuffer();
// address.append("sms://");
// address.append(mReceiver);
// if (mPort != null) {
// address.append(":");
// address.append(mPort);
// }

// MessageConnection conn = null;
// conn = (MessageConnection) Connector.open(address.toString());
// TextMessage txtmessage = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
// txtmessage.setPayloadText(msgString);
// conn.send(txtmessage);
// conn.close();
// }
}
